﻿using Ken_WPF_UI.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ken_WPF_UI.View.otherUI
{
    /// <summary>
    /// WechatWindow.xaml 的交互逻辑
    /// </summary>
    public partial class WechatWindow : Window
    {
        private WechatModel wechatModel = new WechatModel();

        public WechatWindow()
        {
            InitializeComponent();
        }


        /// <summary>
        /// 隐藏尾部
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBar_Loaded(object sender, RoutedEventArgs e)
        {
            ToolBar toolBar = sender as ToolBar;
            var overflowGrid = toolBar.Template.FindName("OverflowGrid", toolBar) as FrameworkElement;
            if (overflowGrid != null)
            {
                overflowGrid.Visibility = Visibility.Collapsed;
            }

            var mainPanelBorder = toolBar.Template.FindName("MainPanelBorder", toolBar) as FrameworkElement;
            if (mainPanelBorder != null)
            {
                mainPanelBorder.Margin = new Thickness(0);
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            wechatModel.Placeheight = leftMenu.ActualHeight - leftTbTop.ActualHeight - leftTbBottom.ActualHeight- leftTbTop.Margin.Top- leftTbTop.Margin.Bottom;

            List<WxUser> list = new List<WxUser>();
            Random random = new Random();
            string[] sexs = { "meinv01.png", "meinv02.png", "shuaige01.png", "shuaige02.png" };
            WxUser wxUser;
            for (int i = 0; i < 20; i++)
            {
                wxUser = new WxUser() { UserName=$"张{i+1}鸣",Avatar= $"pack://application:,,,/Assets/Images/{sexs[random.Next(0, 4)]}" };
                Console.WriteLine(wxUser.Avatar);
                wxUser.LastChatMsg = $"与张{i + 1}鸣最新聊天记录...";
                list.Add(wxUser);
            }

            wechatModel.UserList = list;

            this.DataContext = wechatModel;

            this.userMenuList.DataContext = wechatModel;
        }

        private void userMenuList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ListBox listBox = sender as ListBox;
            WxUser wxUser = listBox.SelectedItem as WxUser;
            this.concactUser.Content = wxUser.UserName;
            Console.WriteLine("-----");   
        }

        private void Button_MouseEnter(object sender, MouseEventArgs e)
        {
            sendBtn.Background = new SolidColorBrush(Colors.Red);
        }

        private void Button_MouseLeave(object sender, MouseEventArgs e)
        {
            sendBtn.Background = new SolidColorBrush(Color.FromRgb(221, 221, 221));
        }

       /* private void userMenuList_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            Decorator decorator = (Decorator)VisualTreeHelper.GetChild(userMenuList, 0);
            ScrollViewer scrollViewer = (ScrollViewer)decorator.Child;
            scrollViewer.ScrollToEnd();
        }*/
    }
}
